package solpro;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;

public class MainStart {

	private static int iNewVersion = 0; //0=close 1=newVersion 2=oldVersion 
	private Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="90,15"
	private Composite composite = null;
	private Label label = null;
	private Button buttonNewPlayer = null;
	private Button buttonOltPlayer = null;

	/**
	 * This method initializes composite	
	 *
	 */
	private void createComposite() {
		GridData gridData4 = new GridData();
		gridData4.grabExcessHorizontalSpace = true;
		gridData4.verticalAlignment = GridData.CENTER;
		gridData4.horizontalAlignment = GridData.BEGINNING;
		GridData gridData3 = new GridData();
		gridData3.horizontalAlignment = GridData.BEGINNING;
		gridData3.grabExcessHorizontalSpace = true;
		gridData3.verticalAlignment = GridData.CENTER;
		GridData gridData2 = new GridData();
		gridData2.horizontalAlignment = GridData.END;
		gridData2.verticalAlignment = GridData.CENTER;
		GridData gridData1 = new GridData();
		gridData1.horizontalSpan = 5;
		gridData1.verticalAlignment = GridData.CENTER;
		gridData1.grabExcessHorizontalSpace = true;
		gridData1.horizontalAlignment = GridData.CENTER;
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 5;
		GridData gridData = new GridData();
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalAlignment = GridData.FILL;
		gridData.verticalAlignment = GridData.FILL;
		gridData.grabExcessVerticalSpace = true;
		composite = new Composite(sShell, SWT.NONE);
		composite.setLayoutData(gridData);
		composite.setLayout(gridLayout);
		label = new Label(composite, SWT.NONE);
		label.setText("Please select your SOLISTEN player!");
		label.setLayoutData(gridData1);
		label.setFont(new Font(Display.getDefault(), "Tahoma", 12, SWT.NORMAL));
		Label filler4 = new Label(composite, SWT.NONE);
		Label filler1 = new Label(composite, SWT.NONE);
		filler1.setLayoutData(gridData3);
		Label filler = new Label(composite, SWT.NONE);
		Label filler7 = new Label(composite, SWT.NONE);
		Label filler2 = new Label(composite, SWT.NONE);
		filler2.setLayoutData(gridData4);
		Label filler8 = new Label(composite, SWT.NONE);
		filler8.setLayoutData(gridData4);
		buttonNewPlayer = new Button(composite, SWT.NONE);
		buttonNewPlayer.setText("New player");
		buttonNewPlayer.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/solpro/Solisten_neu.jpg")));
		buttonNewPlayer.setFont(new Font(Display.getDefault(), "Tahoma", 10, SWT.NORMAL));
		buttonNewPlayer
				.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
					public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
						iNewVersion=1; // Neue Version
						sShell.dispose();
					}
				});
		Label filler6 = new Label(composite, SWT.NONE);
		filler6.setLayoutData(gridData4);
		buttonOltPlayer = new Button(composite, SWT.NONE);
		buttonOltPlayer.setText("Old player");
		buttonOltPlayer.setFont(new Font(Display.getDefault(), "Tahoma", 10, SWT.NORMAL));
		buttonOltPlayer.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/solpro/Solisten_alt.jpg")));
		buttonOltPlayer.setLayoutData(gridData2);
		buttonOltPlayer
				.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
					public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
						iNewVersion=2; // Alte Version
						sShell.dispose();
					}
				});
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		/* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)
		 * for the correct SWT library path in order to run with the SWT dlls. 
		 * The dlls are located in the SWT plugin jar.  
		 * For example, on Windows the Eclipse SWT 3.1 plugin jar is:
		 *       installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar
		 */
		Display display = Display.getDefault();
		MainStart thisClass = new MainStart();
		thisClass.createSShell();
		thisClass.sShell.open();
		thisClass.sShell.layout();
		while (!thisClass.sShell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		
		
		switch (iNewVersion) {
		case 0:
			
			break;
		case 1:
			MainWindowSolpro2 newPlayer = new MainWindowSolpro2();
			newPlayer.createSShell();
			newPlayer.sShell.open();
			newPlayer.loadPod();
			while (!newPlayer.sShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			
			break;
		case 2:
			MainWindowSolpro1 oldPlayer = new MainWindowSolpro1();
			oldPlayer.createSShell();
			oldPlayer.sShell.open();
			oldPlayer.loadPod();
			while (!oldPlayer.sShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			
			break;
		default:
			break;
		}
		display.dispose();
	}

	/**
	 * This method initializes sShell
	 */
	private void createSShell() {
		sShell = new Shell(SWT.DIALOG_TRIM);
		sShell.setText(Constants.msgMainStartTitle);
		sShell.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/solpro/solisten_logo.ico")));
		createComposite();
		sShell.setSize(new Point(792, 256));
		sShell.setLayout(new GridLayout());
	}

}
